<template>
	<view>
		<view class="faddishBaner"><image src="/static/images/banner2.png"></image></view>
		
		<view class="recommend">
			<block v-if="newList.length>0">
				<recommend :hostProduct='newList'></recommend>
				<uni-load-more :status="loadStatus"></uni-load-more>
			</block>
			<block v-else>
				<view class="emptyimg">
					<image src="/static/images/noCart.png"></image>
				</view>
			</block>
		</view>	
	</view>
</template>

<script>
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import recommend from '@/components/recommend/col.vue';
	export default {
		components: {
			recommend,
		},
		data() {
			return {
				pagenum: 1, // 页码值
				pagesize: 20, // 每页显示多少条数据
				loading: true,
				loadStatus: 'more',
				newList:[]
			};
		},
		onLoad() {
			this.getNewerData()
		},
		methods:{
			getNewerData() {
				this.$api.getProductNew({
					pagenum: this.pagenum,
					limit:this.pagesize
				},res => {
					if (res.status == 200) {
						this.newList = [...this.newList,...res.data.list];
						this.newList.forEach(item => {
							item.integral = parseFloat(item.integral)
						})
						if (res.data.list.length >= this.pagesize) {
							this.loadStatus = 'more';
							this.pagenum++;
						} else {
							// 数据已加载完毕
							this.loadStatus = 'noMore';
						}
					} else {
						this.loadStatus = 'noMore';
					}
				})
			}
		},
		onReachBottom() {
			if (this.loadStatus === 'more') {
				this.getProductNew()
			}
		}
	}
</script>

<style lang="less">
.faddishBaner {
	height: 346rpx;
	image {
		width: 100%;
		height: 100%;
	}
}
.recommend {
	margin-top: 20rpx;
	.emptyimg {
		width: 414rpx;
		height: 336rpx;
		margin: 78rpx auto 56rpx auto;
	}
}
</style>
